//
//  SubmitView.m
//  Project two framework
//
//  Created by rimi on 16/7/31.
//  Copyright © 2016年 张峥. All rights reserved.
//

#import "SubmitView.h"
#import "ZZConfig.h"
@implementation SubmitView

+ (instancetype)showOtherView
{
    static SubmitView *submitView = nil;
    submitView = [[SubmitView alloc]init];
    return submitView;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT);
        self.backgroundColor = [UIColor blackColor];
        self.alpha = 0.2;
        [self addOtherView];
    }
    return self;
}

- (void)addOtherView
{
    UIWindow *kewWindow = [[UIApplication sharedApplication] keyWindow];
    [kewWindow addSubview:self];
    [kewWindow addSubview:self.imageView];
    [self.imageView addSubview:self.nameLabel];
    [self.imageView addSubview:self.closeBtn];
    [self.imageView addSubview:self.submitBtn];
    [self addLabel];
    [self addOtherLabel];
    [self addUIImageView];
    [self addTextField];
    [UIView animateWithDuration:0.5 animations:^{
        self.alpha = 0.6;
        self.frame = SCREEN_Bounds;
        self.imageView.frame = CGRectMake(80 , 100, SCREEN_WIDTH - 160, SCREEN_HEIGHT - 200);
    }];
    
}

#pragma mark - 按钮的功能实现
- (void)submitAction:(UIButton *)sender
{
    
}

- (void)closeBtnAction
{
    [UIView animateWithDuration:0.5 animations:^{
        self.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT);
        self.imageView.frame = CGRectMake(80 , 100 + SCREEN_HEIGHT, SCREEN_WIDTH - 160, SCREEN_HEIGHT - 200);
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
        [self.imageView removeFromSuperview];
    }];
}

#pragma mark -  懒加载
- (UIImageView *)imageView
{
    if (_imageView == nil) {
        _imageView = ({
            UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(80 , 100 + SCREEN_HEIGHT, SCREEN_WIDTH - 160, SCREEN_HEIGHT - 200)];
            imageView.image = [UIImage imageNamed:@"底_05.png"];
            imageView.userInteractionEnabled = YES;
            imageView;
        });
    }
    return _imageView;
}

- (UIButton *)closeBtn
{
    if (_closeBtn == nil) {
        _closeBtn = ({
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            [btn setImage:[UIImage imageNamed:@"close_07.png"] forState:UIControlStateNormal];
            btn.frame = CGRectMake(CGRectGetMaxX(self.imageView.bounds) - 60, 15, 45, 45);
            [btn addTarget:self action:@selector(closeBtnAction) forControlEvents:UIControlEventTouchUpInside];
            btn;
        });
    }
    return _closeBtn;
}

- (UILabel *)nameLabel
{
    if (_nameLabel == nil) {
        _nameLabel = ({
            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(100 , 30, CGRectGetMaxX(self.imageView.bounds) - 200, 50)];
            label.textAlignment = NSTextAlignmentCenter;
            label.font = [UIFont boldSystemFontOfSize:20];
            label.text = @"客户信息录入";
            label;
        });
    }
    return _nameLabel;
}

- (void)addLabel
{
    NSArray *array = @[@"姓名:",@"证件号码:",@"联系电话:"];
    for (NSInteger index = 0 ; index < array.count ; index ++) {
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(140, 110 + index * 80, 90, 40)];
        label.textAlignment = NSTextAlignmentRight;
        label.font = [UIFont boldSystemFontOfSize:20];
        label.text = array[index];
        [self.imageView addSubview:label];
    }
}

- (void)addOtherLabel
{
    NSArray *array = @[@"申请人的名字, 很重要!",@"申请人的证件号, 如身份证等!",@"申请人的电话, 很重要!"];
    for (NSInteger index = 0; index < 3; index ++) {
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(240, 150 + index * 80, 450, 20)];
        label.textAlignment = NSTextAlignmentLeft;
        label.font = [UIFont boldSystemFontOfSize:10];
        label.text = array[index];
        [self.imageView addSubview:label];
    }
}

- (void)addUIImageView
{
    for (NSInteger index = 0; index < 3; index ++) {
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(240, 110 + index * 80, 450, 40)];
        imageView.image = [UIImage imageNamed:@"写入框_08.png"];
        [self.imageView addSubview:imageView];
    }
}

- (void)addTextField
{
    for (NSInteger index = 0; index < 3; index ++) {
        UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(240, 110 + index * 80, 450, 40)];
        textField.textAlignment = NSTextAlignmentLeft;
        textField.font = [UIFont boldSystemFontOfSize:25];
        [self.imageView addSubview:textField];
    }
}

- (UIButton *)submitBtn
{
    if (_submitBtn == nil) {
        _submitBtn = ({
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(350, 400, 160, 50);
            [btn setImage:[UIImage imageNamed:@"提交办理.png"] forState:UIControlStateNormal];
            [btn addTarget:self action:@selector(submitAction:) forControlEvents:UIControlEventTouchUpInside];
            btn;
        });
    }
    return _submitBtn;
}


@end
